package com.mcf.xiaolinju.controller;
import com.mcf.xiaolinju.vo.LoginReturn;
import com.mcf.xiaolinju.service.impl.UserServiceImpl;
import com.mcf.xiaolinju.token.JwtUtil;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;


@RestController
@CrossOrigin
@RequestMapping("/xiaolinju/user")
public class UserController {
    @Resource
    UserServiceImpl userService;

    //WEB端登录
    @RequestMapping("/login")
    public LoginReturn login(String username, String password, String code) {
        return userService.selectByUsernamePassword(username, password, code);
    }

    @RequestMapping("/gettoken")
    public String gettoken(int id, String name) {
        JwtUtil jwtUtil = new JwtUtil();

        return jwtUtil.getTokn(id, name);
    }

    //小程序端登录
    @RequestMapping("/applogin")
    public LoginReturn applogin(String username, String password) {
        return userService.applogin(username, password);
    }

    //验证输入的旧密码是否正确
    @RequestMapping("/validation")
    public String getPassword(int id, String pass) {
        return userService.getPassword(id, pass);
    }

    //修改密码
    @RequestMapping("/updatepassword")
    public String updatePassword(int id, String password, int updateid) {
        return userService.updatePassword(id, password, updateid);
    }

    //通过用户名查询用户的数量
    @RequestMapping("/getUserCount")
    public int getUserCount(String username) {
        return userService.getUserCount(username);
    }

    //小程序通过用户名得到账户信息
    @RequestMapping("/getUserAPI")
    public LoginReturn getUserAPI(String username) {
        return userService.getUserAPI(username);
    }

    //通过用户名修改密码
    @RequestMapping("/updatePasswordByUsername")
    public String updatePasswordByUsername(String username, String password) {
        return userService.updatePasswordByUsername(username, password);
    }

    //小程序添加用户信息
    @RequestMapping("/insertusermessage")
    String insertusermessage(String username, String password, int role, String mastername, String idcardnumber, int communityid, String unitnum, int buildingnum, int housenum, String phonenum) {
        return userService.insertusermessage(username, password, role, mastername, idcardnumber, communityid, unitnum, buildingnum, housenum, phonenum);
    }
}